package com.blogs;

import com.blogs.common.redis.interceptor.CacheKeyGenerator;
import com.blogs.common.redis.interceptor.LockKeyGenerator;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * @Author: xiaokai
 * @Description:
 * @Date: 2019/5/23
 * @Version: 1.0
 */
@SpringBootApplication
public class WebApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class, args);
    }

    /**
     * redisson分布式锁配置
     * @return
     */
    @Bean
    public Redisson redisson(){
        //此为单机模式
        Config config = new Config();
        config.useSingleServer().setAddress("redis://129.204.172.12:6379").setDatabase(0);
        return (Redisson) Redisson.create(config);

    }

    /**
     * 在主函数内注入定义好的CacheKeyGenerator 接口
     * @return
     */
    @Bean
    public CacheKeyGenerator cacheKeyGenerator() {
        return new LockKeyGenerator();
    }

}
